package com.adb.entity;

import android.content.Context;

import com.adb.dao.GameDraftManager;
import com.jjmmbb.jxSudoku.Comm;

public class DataRect {
	private int x; // 绘图坐标
	private int y; // 绘图坐标
	public int r;// 行号
	public int l;// 列号
	private int type;// 1：原始,暗灰色格子； 2：默认,白； 3： 当前,可编辑,红 ； 5: 当前,不可编辑,亮灰
	private int data; // 方格内的数字
	private int number; // 81个数中的序号
	private int rectSize; // 方格的大小
	private String draft = ""; // 草稿字符串,样式: 000010001 表示有草稿5,1
	public boolean isAttack = false; // 是否冲突

	public DataRect() {
	}

	public DataRect(int x, int y) {
		ini(x, y, 0, 0, 0, 0, "");
	}

	public DataRect(int x, int y, int rectSize) {
		ini(x, y, rectSize, 0, 0, 0, "");
	}

	public DataRect(int x, int y, int rectSize, int number, int data, int type) {
		ini(x, y, rectSize, number, data, type, "");
	}

	// 带草稿初始化
	public DataRect(int x, int y, int rectSize, int number, int data, int type,
			String draft) {
		ini(x, y, rectSize, number, data, type, draft);
	}

	void ini(int x, int y, int rectSize, int number, int data, int type,
			String draft) {
		this.x = x;
		this.y = y;
		this.rectSize = rectSize;
		this.number = number;
		this.r = number / 9; // 行号
		this.l = number % 9; // 列号
		this.data = data;
		this.type = type;
		this.draft = draft;
	}

	public boolean isSelected(float selX, float selY) {
		if ((selX >= x && selX <= x + rectSize)
				&& (selY >= y && selY <= y + rectSize)) {
			return true;
		}
		return false;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getData() {
		return data;
	}

	public void setData(int data) {
		this.data = data;
	}

	public int getRectSize() {
		return rectSize;
	}

	public void setRectSize(int rectSize) {
		this.rectSize = rectSize;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getDraft() {
		String draftStr = "";
		if (null != draft) {
			for (int i = 0; i < draft.length(); i++) {
				if (draft.charAt(i) == '1') {
					draftStr += " " + (i + 1);
				}
			}
		}
		return draftStr.trim();
	}

	public String getDraftCode() {
		if (null == draft) {
			return "";
		}
		return draft;
	}

	public void setDraft(String draft, Context context) {
		this.draft = draft;
		GameDraftManager gdm = new GameDraftManager();
		GameDraft gameDraft = new GameDraft();
		gameDraft.avID = Comm.currentGameData.av_id;
		gameDraft.num = number;
		gameDraft.draft = draft;
		gdm.save(context, gameDraft);
	}

}
